/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package uni.j2ee.forum.model;

import java.io.Serializable;
import java.util.Collection;
import java.util.Date;
import javax.persistence.*;
import javax.validation.constraints.NotNull;
import javax.validation.constraints.Size;
import javax.xml.bind.annotation.XmlRootElement;
import javax.xml.bind.annotation.XmlTransient;

/**
 *
 * @author Lubomir
 */
@Entity
@Table(name = "TOPICS")
@XmlRootElement
@NamedQueries({
    @NamedQuery(name = "ForumTopic.findAll", query = "SELECT f FROM ForumTopic f"),
    @NamedQuery(name = "ForumTopic.findByTopicId", query = "SELECT f FROM ForumTopic f WHERE f.topicId = :topicId"),
    @NamedQuery(name = "ForumTopic.findByTopicDate", query = "SELECT f FROM ForumTopic f WHERE f.topicDate = :topicDate"),
    @NamedQuery(name = "ForumTopic.findByCategory", query = "SELECT f FROM ForumTopic f WHERE f.catId = :category")
})
public class ForumTopic implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.IDENTITY)
    @Basic(optional = false)
    @Column(name = "topic_id")
    private Integer topicId;
    @Lob
    @Size(max = 32700)
    @Column(name = "title")
    private String title;
    @Column(name = "topic_date")
    @Temporal(TemporalType.DATE)
    private Date topicDate;
    @JoinColumn(name = "username", referencedColumnName = "username")
    @ManyToOne
    private ForumUser username;
    @JoinColumn(name = "cat_id", referencedColumnName = "cat_id")
    @ManyToOne
    private Category catId;
    @OneToMany(mappedBy = "topicId")
    private Collection<ForumPost> forumPostCollection;

    public ForumTopic() {
    }

    public ForumTopic(Integer topicId) {
        this.topicId = topicId;
    }

    public Integer getTopicId() {
        return topicId;
    }

    public void setTopicId(Integer topicId) {
        this.topicId = topicId;
    }

    public String getTitle() {
        return title;
    }

    public void setTitle(String title) {
        this.title = title;
    }

    public Date getTopicDate() {
        return topicDate;
    }

    public void setTopicDate(Date topicDate) {
        this.topicDate = topicDate;
    }

    public ForumUser getUsername() {
        return username;
    }

    public void setUsername(ForumUser username) {
        this.username = username;
    }

    public Category getCatId() {
        return catId;
    }

    public void setCatId(Category catId) {
        this.catId = catId;
    }

    @XmlTransient
    public Collection<ForumPost> getForumPostCollection() {
        return forumPostCollection;
    }

    public void setForumPostCollection(Collection<ForumPost> forumPostCollection) {
        this.forumPostCollection = forumPostCollection;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (topicId != null ? topicId.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof ForumTopic)) {
            return false;
        }
        ForumTopic other = (ForumTopic) object;
        if ((this.topicId == null && other.topicId != null) || (this.topicId != null && !this.topicId.equals(other.topicId))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "uni.j2ee.forum.model.ForumTopic[ topicId=" + topicId + " ]";
    }
    
}
